package org.rabbitmq.orderservice.controller;

import org.rabbitmq.orderservice.util.OrderInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    public RabbitTemplate rabbitTemplate;
    @RequestMapping("/create")
    public String create(){
        //发送消息:
        String id = UUID.randomUUID().toString();
        //使用内置交换机
        rabbitTemplate.convertAndSend("","order.queue","下单成功,订单id为:"+id);
        return "OK";
    }


    @RequestMapping("/create2")
    public String create2(){
        //发送消息:
        OrderInfo orderInfo = new OrderInfo();
        String id = UUID.randomUUID().toString();
        orderInfo.setOrderId(id);
        orderInfo.setName("商品");
        //使用内置交换机
        rabbitTemplate.convertAndSend("","order.queue",orderInfo);
        return "OK";
    }

}
